<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\pay\controller;

use cmf\controller\AdminBaseController;
use think\db\Query;
use think\facade\Db;

class MoneylogController extends AdminBaseController
{

    /**
     * Notes:vip列表
     * User:
     * DateTime: 2022-01-17 14:57
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function index()
    {
        $param = $this->request->param();
        $list = Db::name("moneylog")->alias('r')
            ->field("r.*,m.user_login")
            ->leftJoin("user m", "r.user_id = m.id")
            ->where(function (Query $query) use ($param) {
                if (isset($param['start_time']) && !empty($param['start_time'])) {
                    if (!isset($param['end_time']) || empty($param['end_time'])) {
                        $param['end_time'] = time();
                    }
                    $query->whereTime('r.create_time', 'between', [$param['start_time'], $param['end_time']]);
                }
                if (isset($param['user_login']) && !empty($param['user_login'])) {
                    $query->where('m.user_login', 'like', "%" . $param['user_login'] . "%");
                }
                if (isset($param['type']) && $param['type'] != '') {
                    $query->where(['r.type' => $param['type']]);
                }
            })
            ->order("r.id desc")
            ->paginate(30);
        $page = $list->render();
        $this->assign("page", $page);
        $this->assign("list", $list);
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign('user_login', isset($param['user_login']) ? $param['user_login'] : '');
        $this->assign('type', isset($param['type']) ? $param['type'] : '');
        return $this->fetch();
    }

    /**
     * 删除
     * @return void
     * @throws \think\db\exception\DbException
     */
    public function deleteAgree()
    {
        $id = $this->request->param('id', 0, 'intval');
        Db::name("moneylog")->where('id', $id)->delete();
        $this->success("删除成功");
    }

}
